package thread;

/**
 * 以匿名内部类形式完成线程的两种创建
 * */
public class ThreadDemo3 {
    public static void main(String[] args) {

        //第一种创建方式：继承Thread重写run方法
        Thread t1 = new Thread(){
            public void run(){
                for (int i = 0; i < 100; i++){
                    System.out.println("你是谁？");
                }
            }
        };
        //lambda表达式：
       /* Thread t1 = new Thread(()->{
                for (int i = 0; i < 100; i++){
                    System.out.println("你是谁？");
                }
        });*/


        //第二种创建方式：实现Runnable接口，重写run方法
      /*  Runnable r2 =new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 100; i++){
                    System.out.println("查水表");
                }
            }
        };
        Thread t2 = new Thread(r2);
        */


        //lambda 表达式:
/*
           Runnable r2 = ()->{
            for (int i = 0; i < 1000; i++) {
                System.out.println("查水表!");
            }
        };
        Thread t2 = new Thread(r2);*/

        Thread t2 = new  Thread(()-> {
                for (int i = 0; i < 1000; i++) {
                    System.out.println("查水表!");
                }
        });


        t1.start();
        t2.start();
    }

}


